


/**
 * 预加载
 * @param {Object} arr
 * @param {Object} cb
 */
function loaders(arr, cb) {
    var len = arr.length,
        loadIndex = 0,
        per = $("#percent");
    arr.forEach(function (item) {
        var img = new Image;
        img.onload = function () {
            loadIndex++;
            var p = parseInt(loadIndex / len * 100);
            per.text(p + "%");
            if (loadIndex >= len) {
                setTimeout(function () {
                    cb && cb();
                }, 100);
            }
        }
        img.src = imagesUrl + item;
    });
}


/**
 * 显示通用弹窗
 * @param {Object} str1 大字
 * @param {Object} str2    小字，可插入html字符
 */
function showAlert(str1, str2) {
    var s1 = str1 ? str1 : "",
        s2 = str2 ? str2 : "";
    $(".alert-common .alert-title h3").text(s1);
    $(".alert-common .alert-title p").html(s2);
    $(".alert-common").removeClass("hide");
}


/**
 * 判断手机号
 * @param {Object} str
 */
function isPhone(str) {
    if (typeof str === 'number') {
        str = str.toString();
    }
    return /^0?1[3|4|5|7|8][0-9]\d{8}$/.test(str);
}



/**
 * 停止计时
 * @param {Object} cb
 */
function stopTimer(cb) {
    clearInterval(battleTimer);
    cb && cb();
}

/**
 * 初始化页面
 */
function initPage() {
    loaders(loadArr, function () {
        $(".loading").remove();
        $(".index").removeClass("hide");
    });
}


/**
 * cookie方法
 */
var Cookie = {
    get: function (key) {
        try {
            var arr = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)"));
            if (arr != null) {
                return decodeURIComponent(arr[2]);
            }
        } catch (e) {
        }
        return null;
    },
    set: function (key, value, date, domain) {
        try {
            domain = domain ? (';domain=' + domain) : '';
            var Days = date ? date * 1000*60*60*24 : 60*1000*60;
            var exp = new Date();
            exp.setTime(exp.getTime() + Days);
            document.cookie = key + "=" + encodeURIComponent(value) + domain + ";expires=" + exp.toGMTString() + ";path=/";
        } catch (e) {
        }
    },
    remove: function (key, domain) {
        this.set(key, "", -24 * 60 * 60, domain);
    }
}

/**
 * 判断输入空
 * @param {Object} str
 */
function isEmpty(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "") ? false : true;
}



/**
 * 连一连提示
 */
function showTips(){
	if(Cookie.get("__linktips__") == 1){
		$(".linkTips").addClass("hide");
	}else{
		$(".linkTips").removeClass("hide");
		Cookie.set("__linktips__",1,365);
	}
}




function initGuanqia(total = 300, act = 0){
    var  li = "";
    for(var i = 0 ; i< 600; i ++){
        li  += "<li "+(i <= act ? "class='active'" : "")+"><span>"+(i+1)+"</span></li>"
    }
    $(".guanqia-list").html(li)
}

initPage();